package cn.wolfcode.luowowo.scenic.service.impl;

import cn.wolfcode.luowowo.scenic.domain.Scenic;
import cn.wolfcode.luowowo.scenic.mapper.ScenicMapper;
import cn.wolfcode.luowowo.scenic.query.ScenicQuery;
import cn.wolfcode.luowowo.scenic.service.IScenicService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service
public class ScenicServiceImpl implements IScenicService{
    @Autowired
    private ScenicMapper scenicMapper;
    public List<Scenic> getScenicByDestId(Long destId) {
        List<Scenic> scenics=scenicMapper.selectByDestId(destId);
        return scenics;
    }

    public List<Scenic> getScenicByParentId(Long scenicId) {
        List<Scenic> scenics=scenicMapper.selectByScenicId(scenicId);
        return scenics;
    }

    public List<Scenic> getHotScenicByDestId(Long destId, int scenicHot) {
        List<Scenic> scenics=scenicMapper.selectHotScenicByDestId(destId,scenicHot);
        return scenics;
    }

    public List<String> getCoverImgUrl(Scenic scenic) {
        String coverUrl = scenic.getCoverUrl();
        String[] split = coverUrl.split(";");
        List<String> list=new ArrayList<>();
        for (String s : split) {
            list.add(s);
        }
        return list;
    }

    public Scenic getDetail(Long scenicId) {
        Scenic scenic=scenicMapper.selectByPrimaryKey(scenicId);
        return scenic;
    }

    public List<Scenic> getScenicByInterior(Long scenicId) {
        List<Scenic> scenics=scenicMapper.selectScenicByInterior(scenicId);
        return scenics;
    }

    public List<Scenic> getByDestId(Long destId) {
        List<Scenic> scenics = scenicMapper.selectAll();
        return scenics;
    }

    public Scenic getById(long id) {
        return scenicMapper.selectByPrimaryKey(id);
    }

    public void updateReplyNum(Integer count,Long scenicDetailId) {
        scenicMapper.updateReplyNum(count,scenicDetailId);
    }

    public PageInfo query(ScenicQuery qo,Long destId) {
        List<Scenic> scenics=new ArrayList<>();
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Scenic> list = scenicMapper.selectByTagId(qo);
        for (Scenic scenic : list) {
            Long id=scenic.getDest().getId();
            System.out.println(id);
            System.out.println(destId);
            if(scenic.getDest().getId().longValue()==destId.longValue()){
                scenics.add(scenic);
            }

        }
        return new PageInfo(scenics);
    }

    public Scenic get(Long id) {
        Scenic scenic = scenicMapper.selectByPrimaryKey(id);
        return scenic;
    }

    public List<Scenic> list() {
        return scenicMapper.selectAll();
    }

    /*public PageInfo queryScenic(ScenicQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Scenic> scenics = scenicMapper.selectForList(qo);
        return new PageInfo(scenics);
    }*/



    public List<Scenic> getTop3Scenic(Long destId) {
        return scenicMapper.getTop3Scenic(destId);
    }



}
